import { detailConfig } from '@/views/datacenter/business/elderlyFacilitiesRating/config'

export default defineComponent({
	props: {
		nowRowData: {
			type: Object,
			defalut: () => ({}),
		},
	},
	setup(props) {
		const tableConfig = {
			stripe: true,
			border: true,
			maxHeight: '80vh',
			columns: [
				{
					type: 'expand',
					render: ({ row }) => {
						console.log('=-===', row)
						// 处理占比
						row.totalScore =
							row.overallRequir +
							row.qualificationCond +
							row.basicFunction +
							row.serviceItem +
							row.servicePerformance +
							row.securityGuarantee +
							row.infrastructure +
							row.staffing +
							row.regulations +
							row.supervisionManagement
						row.overallRequirRate = ((row.overallRequir / row.totalScore) * 100).toFixed(2)
						row.qualificationCondRate = ((row.qualificationCond / row.totalScore) * 100).toFixed(2)
						row.basicFunctionRate = ((row.basicFunction / row.totalScore) * 100).toFixed(2)
						row.serviceItemRate = ((row.serviceItem / row.totalScore) * 100).toFixed(2)
						row.servicePerformanceRate = ((row.servicePerformance / row.totalScore) * 100).toFixed(2)
						row.securityGuaranteRate = ((row.securityGuarantee / row.totalScore) * 100).toFixed(2)
						row.securityGuaranteRate = ((row.securityGuarantee / row.totalScore) * 100).toFixed(2)
						row.infrastructureRate = ((row.infrastructure / row.totalScore) * 100).toFixed(2)
						row.staffingRate = ((row.staffing / row.totalScore) * 100).toFixed(2)
						row.regulationsRate = ((row.regulations / row.totalScore) * 100).toFixed(2)
						row.supervisionManagementRate = ((row.supervisionManagement / row.totalScore) * 100).toFixed(2)

						return (
							<div style="width: 40vw;margin: 0 auto;">
								<el-descriptions column={2}>
									<el-descriptions-item label="等级评定星级">{row.assessmentLevelLabel}星级</el-descriptions-item>
									<el-descriptions-item label="现场评定总分">
										{row.totalScore}分
										<div class="flex align-center">
											<el-button size="small" onClick={() => handleShowDetail(row)}>
												点击查看评定明细
											</el-button>
										</div>
									</el-descriptions-item>
									<el-descriptions-item label="总体要求">
										<span>
											{row.overallRequir}分 得分占比 {row.overallRequirRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="资质条件">
										<span>
											{row.qualificationCond}分 得分占比 {row.qualificationCondRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="基本职能">
										<span>
											{row.basicFunction}分 得分占比 {row.basicFunctionRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="服务项目">
										<span>
											{row.serviceItem}分 得分占比 {row.serviceItemRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="服务绩效">
										<span>
											{row.servicePerformance}分 得分占比 {row.servicePerformanceRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="安全保障">
										<span>
											{row.securityGuarantee}分 得分占比 {row.securityGuaranteRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="基础设施">
										<span>
											{row.infrastructure}分 得分占比 {row.infrastructureRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="人员配备">
										<span>
											{row.staffing}分 得分占比 {row.staffingRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="规章制度">
										<span>
											{row.regulations}分 得分占比 {row.regulationsRate}%
										</span>
									</el-descriptions-item>
									<el-descriptions-item label="监督管理">
										<span>
											{row.supervisionManagement}分 得分占比 {row.supervisionManagementRate}%
										</span>
									</el-descriptions-item>
								</el-descriptions>
							</div>
						)
					},
				},
				{
					label: '申报时间',
					prop: 'declareTime',
				},
				{
					label: '评定时间',
					prop: 'createTime',
				},
				{ label: '评定等级', prop: 'assessmentLevelLabel' },
				{ label: '评定结果', prop: 'assessmentResultLabel' },
			],
		}

		const crud = ref()
		const handleShowDetail = (row) => {
			nextTick(() => {
				crud.value.handleOperate('detail', row, '详情')
			})
		}
		// 接受prop参数
		let soleValue = props.nowRowData.soleValue || ''
		let params = {
			soleValue: soleValue,
			isWithAuth:0
		}
		const baseConfig = {
			pageName: '机构等级评定档案',
			rowKey: 'id',
			api: {
				index: 'view_dpServiceFacilitiesLevelEvaluate_page',
			},
			auth: {
				index: 'view_dpServiceFacilitiesLevelEvaluate_page',
			},
			menuBtn: [
				{
					icon: 'editor',
					label: '查看档案',
					type: 'primary',
					operate: 'detail',
					auth: '',
					text: true,
					show: true,
				},
			],
		}

		return () => (
			<aplid-base-crud
				ref={crud}
				api={baseConfig.api}
				pageName={baseConfig.pageName}
				rowKey={baseConfig.rowKey}
				auth={baseConfig.auth}
				tableConfig={tableConfig}
				detailConfig={detailConfig}
				paramsObj={params}
			/>
		)
	},
})
